package com.my.study.loader;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author: yidujun
 * @create: 2022/01/15 10:54
 */
public class ClassLoaderTest {

    public static void main(String[] args) {
//        ClassLoader classLoader = Test.class.getClassLoader();
//
//        System.out.println("ClassLoader is : " + classLoader.toString());
//        System.out.println("ClassLoad parent is : " + classLoader.getParent().toString());
//
//        System.out.println(int.class.getName());
//        System.out.println(int.class.getClassLoader());

//        FileUtils.test("D:/file/class/Test.class");

        String path = "D:/file/class";
        DeClassLoader custom = new DeClassLoader(path);

        try {
            Class<?> loadClass = custom.loadClass("com.my.study.loader.Test");
            if (null != loadClass) {
                Object instance = loadClass.newInstance();
                Method say = loadClass.getDeclaredMethod("say", null);
                say.invoke(instance, null);
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

    }

}
